package com.aiti.lulian.controller;

import com.aiti.base.core.base.controller.BaseController;
import com.aiti.base.core.utils.message.Message;
import com.aiti.lulian.dto.CardUserCardSettingDto;
import com.aiti.lulian.entity.CardUserBackground;
import com.aiti.lulian.service.CardUserCardSettingService;
import com.aiti.lulian.vo.CardUserCardSettingDetailVo;
import com.aiti.lulian.vo.CardUserCardSettingVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 个人名片设置表 前端控制器
 * </p>
 *
 * @author 
 * @since 2025-08-11
 */
@RestController
@RequestMapping("/user-card-setting")
public class CardUserCardSettingController extends BaseController {
    @Autowired
    private CardUserCardSettingService cardUserCardSettingService;

    @PostMapping("/save")
    public Message saveSetting(@Validated @RequestBody CardUserCardSettingDto dto) {
        cardUserCardSettingService.saveSetting(dto);
        return Message.success();
    }

    @GetMapping("/userSetting")
    public Message userSetting(@RequestParam(value = "userId", required = false) String userId, @RequestParam(value = "cardId", required = false) String cardId) {
        CardUserCardSettingVo vo = cardUserCardSettingService.getTemplateSettingByUserId(userId, cardId);
        return Message.success(vo);
    }

    @GetMapping("/userSettingDetail")
    public Message userSettingDetail(@RequestParam("userId") String userId, @RequestParam("cardId") String cardId) {
        CardUserCardSettingDetailVo vo = cardUserCardSettingService.userSettingDetail(userId, cardId);
        return Message.success(vo);
    }


    @GetMapping("/backgroundList")
    public Message backgroundList(@RequestParam("templateId") String templateId) {
        List<CardUserBackground> cardUserBackgrounds = cardUserCardSettingService.backgroundList(templateId);
        return Message.success(cardUserBackgrounds);
    }

    /**
     * 更新名片转发封面图
     */
    @PutMapping("/update-forward-cover")
    public Message updateForwardCoverUrl(@RequestBody CardUserCardSettingDto dto) {
        cardUserCardSettingService.updateForwardCoverUrl(dto);
        return Message.success();
    }
}
